package com.ltx.text.vo;

import lombok.Data;

/**
 * Rest请求标准响应结构体
 */
@Data
public class RestResultVo<T> {
    /*
     * 状态码(200成功)
     */
    private int code;
    /**
     * 错误消息
     */
    private String message;
    /**
     * 响应内容
     */
    private T data;

    public static <T> RestResultVo<T> success(){
        RestResultVo<T> resultVo = new RestResultVo<>();
        resultVo.setCode(200);
        return resultVo;
    }
    public static <T> RestResultVo<T> ok(T data) {
        RestResultVo<T> resultVo = new RestResultVo<>();
        resultVo.setCode(200);
        resultVo.setData(data);
        return resultVo;
    }
    public static <T> RestResultVo<T> bad(){
        RestResultVo<T> resultVo = new RestResultVo<>();
        resultVo.setCode(404);
        return resultVo;
    }
    public static <T> RestResultVo<T> failed(String msg) {
        RestResultVo<T> resultVo = new RestResultVo<>();
        resultVo.setCode(404);
        resultVo.setMessage(msg);
        return resultVo;
    }
}
